import QtQuick 2.0

// 多级页面路径显示
Item {

    id: root

    height: 30*dp
    width: layout_row.implicitWidth

    property var list: []

    function push(item){
        list.push(item)
        listChanged()
    }
    function pop(){
        list.pop()
        listChanged()
    }
    function getListString(){
        var res = ""
        for(let i = 0; i < list.length; i ++){
            res += list[i]
            if(i < list.length - 1){
                res += "/"
            }
        }
        return res
    }

    Row{
        id: layout_row
        height: root.height

        Repeater{

            model: list.length
            delegate: delegateComponent
        }

    }

    Component{
        id: delegateComponent
        Item{
            id: item
            property bool isHovered: false

            height: root.height
            width: text_content.contentWidth + 30*dp
            Text{
                id: text_content
                text: list[index]
                font.bold: item.isHovered
                anchors.verticalCenter: parent.verticalCenter
                color: item.isHovered ? config.themeColor : "#888888"
                font.pixelSize: config.fontsize
            }
            MouseArea{
                height: text_content.contentHeight
                width: text_content.width
                anchors.verticalCenter: parent.verticalCenter
                hoverEnabled: config.hoverEnabled
                cursorShape: "PointingHandCursor"
                onEntered: {
                    item.isHovered = config.hoverEnabled
                }onExited: {
                    item.isHovered = false
                }onClicked: {
                    list = list.slice(0, index+1)
                }
            }

            // 间隔符
            Text{
                id: text_gap
                x: parent.width - 30*dp
                text: "/"
                height: parent.height
                width: 30*dp
                font.bold: true
                color: "#A4A4A4"
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                visible: index !== list.length
                font.pixelSize: config.fontsize
            }
        }

    }






}
